package com.sc.nft.config.fulu.model.request;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * 直充下单请求参数
 *
 * @author liGen
 * @version 1.0
 * @date 2023/11/10 3:06 下午
 */
@Data
public class FuLuOrderDirectRequest {

    /**
     * 商品id
     */
    private Integer productId;

    /**
     * 外部订单号
     */
    private String customerOrderNo;

    /**
     * 充值账号
     */
    private String chargeAccount;

    /**
     * 购买数量
     */
    private Integer buyNum;

    public JSONObject buildParams() {
        JSONObject params = new JSONObject();
        if (Objects.nonNull(productId)) {
            params.put("product_id", productId);
        }
        if (StringUtils.isNotBlank(customerOrderNo)) {
            params.put("customer_order_no", customerOrderNo);
        }
        if (StringUtils.isNotBlank(chargeAccount)) {
            params.put("charge_account", chargeAccount);
        }
        if (Objects.nonNull(buyNum)) {
            params.put("buy_num", buyNum);
        }
        return params;
    }

    public static FuLuOrderDirectRequest build(Integer productId, String customerOrderNo, String chargeAccount, Integer buyNum) {
        FuLuOrderDirectRequest fuLuOrderDirectRequest = new FuLuOrderDirectRequest();
        fuLuOrderDirectRequest.setProductId(productId);
        fuLuOrderDirectRequest.setCustomerOrderNo(customerOrderNo);
        fuLuOrderDirectRequest.setChargeAccount(chargeAccount);
        fuLuOrderDirectRequest.setBuyNum(buyNum);
        return fuLuOrderDirectRequest;
    }
}
